package util.lang;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class TimePlus {
	public static Timestamp AddDays(Timestamp ts,int i) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(ts);
		cal.add(Calendar.DATE, i);
		return Timestamp.valueOf((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(cal.getTime()));
	}
	
	public static Timestamp AddHours(Timestamp ts,int h) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(ts);
		cal.add(Calendar.HOUR, h);
		return Timestamp.valueOf((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(cal.getTime()));
	}
	
	public static Timestamp AddMins(Timestamp ts,int m) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(ts);
		cal.add(Calendar.MINUTE, m);
		return Timestamp.valueOf((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(cal.getTime()));
	}
	
	public static Timestamp AddSeconds(Timestamp ts,int s) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(ts);
		cal.add(Calendar.SECOND, s);
		return Timestamp.valueOf((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(cal.getTime()));
	}
	
	public static Timestamp AddMonth(Timestamp ts,int m) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(ts);
		cal.add(Calendar.MONTH, m);
		return Timestamp.valueOf((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(cal.getTime()));
	}
	
	public static Timestamp AddYear(Timestamp ts,int y) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(ts);
		cal.add(Calendar.YEAR, y);
		return Timestamp.valueOf((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(cal.getTime()));
	}
	
}
